package info.xiao.dataStructrue.array;

/**
 * @Classname FindMaxConsecutiveOnes
 * @Description 最大连续 1 的个数
 * @Url https://leetcode.cn/problems/max-consecutive-ones/
 * @Date 2023/4/7 14:34
 * @Created by 晓龙Oba
 */
public class FindMaxConsecutiveOnes {
    public static void main(String[] args) {
        int[] nums = {1, 1, 0, 1, 1, 1};
        int result = findMaxConsecutiveOnes(nums);
        System.out.println(result);
    }

    private static int findMaxConsecutiveOnes(int[] nums) {

        int maxValue = 0;
        int tmp = 0;
        for (int i = 0; i < nums.length; i++) {
            if (nums[i] != 0) {
                tmp++;
                if (tmp > maxValue) {
                    maxValue = tmp;
                }
                continue;
            }
            tmp = 0;
        }

        return maxValue;
    }
}
